package com.epfresh.bean;

import android.util.Log;

import com.epfresh.utils.TimeStringUtils;

public class CountDownTime {
    private String sysDate;
    private String startSubTime;
    private String endSubTime;
    private String subTime;

    private long totalTime;
    private long localeTime;


    public String getSysDate() {
        return this.sysDate;
    }

    public void setSysDate(String sysDate) {
        this.sysDate = sysDate;
    }

    public String getStartSubTime() {
        return this.startSubTime;
    }

    public void setStartSubTime(String startSubTime) {
        this.startSubTime = startSubTime;
    }

    public String getEndSubTime() {
        return this.endSubTime;
    }

    public void setEndSubTime(String endSubTime) {
        this.endSubTime = endSubTime;
    }

    public String getSubTime() {
        return this.subTime;
    }

    public void setSubTime(String subTime) {
        this.subTime = subTime;
    }

    public void setTotalTime(long totalTime) {
        this.totalTime = totalTime;
    }

    public long getLocaleTime() {
        return localeTime;
    }
    public long getTotalTime(){
        return totalTime;
    }

    public void setLocaleTime(long localeTime) {
        this.localeTime = localeTime;
    }

    public long getNowTime() {
        return System.currentTimeMillis();
    }



    public void init(){
        totalTime =  getTotalTime_();
        localeTime = getNowTime();
    }

    public long getTotalTime_(){
        long s = TimeStringUtils.formatTimeLong(startSubTime);
        long e = TimeStringUtils.formatTimeLong(endSubTime);
        return e-s;
    }

    /*
    * @return 0,活动结束;>0活动进行中;<0活动未开始
    * */
    public long getCountDownTime(){
        long tStart = TimeStringUtils.formatTimeLong(startSubTime);
        long tEnd = TimeStringUtils.formatTimeLong(endSubTime);
        long tServer = TimeStringUtils.formatTimeLong(sysDate);

        long tLocale;



/*        if (Math.abs(tServer - localeTime) > 60){
            tLocale = (tServer - localeTime + getNowTime());
        }else {
            tLocale = getNowTime();
        }*/
        tLocale = getNowTime();

        if (tLocale < tStart){//活动未开始
            return tLocale - tStart;
        }else if (tLocale <= tEnd){//活动进行中
            return tEnd - tLocale;
        }else {//活动结束了
            return 0;
        }
//        if (Math.abs(tServer - localeTime) > 60){
//            Log.e("countDown","co::"+(tEnd - (tServer - localeTime + getNowTime())));
//           return tEnd - (tServer - localeTime + getNowTime());
//        }else {
//            Log.e("countDown","co::"+(tEnd - getNowTime()));
//            return tEnd - getNowTime();
//        }

    }



}
